#include "lvgl_wenjian_scan.h"
#include "lvgl_Project.h"

#include <stdlib.h>
#include <windows.h>
#include <direct.h>
#include <io.h>
#include <string.h>

_lvgl_wenjian_scan lvgl_wenjian_scan;


int scan_file(char *pname)
{
	struct _finddata_t stFileInfo;
	long lHandle = 0;
	uint8_t pcPath[300] = { '\0' };
	uint32_t u32Len = 0;
	uint32_t cnt = 0;

	printf("路径:%s\r\n", pname);

	u32Len = 0;
	while (1)
	{
		if (pname[u32Len] == '\\' || pname[u32Len] == '/')
		{
		}
		else if (pname[u32Len] == '\0')  //如果路径字符串到了终点
		{
			break;
		}
		u32Len++;
	}

	memcpy(pcPath, pname, u32Len);

	pcPath[u32Len++] = '*';
	pcPath[u32Len++] = '.';
	pcPath[u32Len++] = '*';
	lHandle = (long)_findfirst(pcPath, &stFileInfo);  //找到第一个文件
	if (lHandle == -1)
	{
		printf("扫描失败:%s\r\n", pname);
		return 1;
	}

	pcPath[--u32Len] = '\0';
	pcPath[--u32Len] = '\0';
	pcPath[--u32Len] = '\0';
	do
	{
		/* 根据文件信息结构体的性质判断文件还是文件夹，文件夹的话就需要进一步分析，递归调用 */
		if (stFileInfo.attrib & _A_SUBDIR) //是目录
		{
			if (stFileInfo.name[0] == '.' && stFileInfo.name[1] == '\0')  //当文件夹是“.”
			{
				continue;
			}
			if (stFileInfo.name[0] == '.' && stFileInfo.name[1] == '.' && stFileInfo.name[2] == '\0')  //当文件夹是“..”
			{
				continue;
			}

			printf("当前是个目录:%s\n", stFileInfo.name);
		}
		else  //是文件
		{

			printf("当前是个文件:%s\n", stFileInfo.name);
		}
		cnt++;
	} while (_findnext(lHandle, &stFileInfo) == 0);
	_findclose(lHandle);

	return cnt;
}

int lvgl_wenjian_scan_scan(char *lujing)
{



}
















